import { Controller } from "../../mvc/core/Controller";
import { IView } from "../../mvc/interfaces/IView";
import { PetPracticeModule } from "../../../modules/PetPracticeModule";
import { WindowEvent } from "../../component/window/WindowEvent";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { SPetInfo } from "../../../Message/Game/SPetInfo";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { SPetUpdate } from "../../../Message/Game/SPetUpdate";
import { SPetStatusUpdate } from "../../../Message/Game/SPetStatusUpdate";
import { IPetPracticeModule } from "../../../modules/interfaces/IPetPracticeModule";
type int = number;
//class PetPracticeController
    
    export  class PetPracticeController extends Controller
    {
        constructor()
        {
            
            super();this.initListener();
            return;
        }

        protected /* override */ initView(): IView
        {
            if (this._practiceModule == null) 
            {
                this._practiceModule = new PetPracticeModule();
                this._practiceModule.addEventListener(WindowEvent.SHOW, this.onPracticeModuleShowHandler);
            }
            return this._practiceModule;
        }

        /* internal  */initListener(): void
        {
            Dispatcher.addEventListener(EventName.PetPractice, this.onPetPracticeHandler);
            Dispatcher.addEventListener(EventName.PetPracticeAcc, this.onPetPracticeAccHandler);
            Dispatcher.addEventListener(EventName.PetGetTrainInfo, this.onPetGetTrainInfoHandler);
            Dispatcher.addEventListener(EventName.PetBagUpdate, this.onPetBagUpdateHandler);
            Dispatcher.addEventListener(EventName.PetStatusUpdate, this.onPetStatusUpdateHandler);
            return;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            return;
        }

        /* internal  */onPracticeModuleShowHandler(arg1: WindowEvent): void
        {
            this._petArray = cache.pet.petInfos.filter(this.filterPracticePet);
            this._practiceModule.updateDataProvider(this._petArray);
            this._practiceModule.resetDefault();
            this.onPetGetTrainInfoHandler(null);
            return;
        }

        /* internal  */filterPracticePet(arg1: SPetInfo, arg2: int, arg3: Array<any>): Boolean
        {
            return arg1.isBorrow == false;
        }

        /* internal  */onPetPracticeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["uid"];
            var loc2=arg1.data["hour"];
            var loc3=arg1.data["type"];
            GameProxy.petProxy.trainPet(loc1, loc2, loc3);
            return;
        }

        /* internal  */onPetPracticeAccHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["uid"];
            var loc2=arg1.data["minutes"];
            var loc3;
            if (loc3 = loc2 == 0) 
            {
                loc2 = 1;
            }
            GameProxy.petProxy.accelerateTrainPet(loc1, loc2, loc3);
            return;
        }

        /* internal  */onPetGetTrainInfoHandler(arg1: DataEvent): void
        {
            GameProxy.petProxy.petTrainInfo();
            return;
        }

        /* internal  */onPetBagUpdateHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SPetUpdate;
            if (this._practiceModule && this._practiceModule.isHide == false) 
            {
                this._practiceModule.updatePet(loc1);
            }
            return;
        }

        /* internal  */onPetStatusUpdateHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SPetStatusUpdate;
            if (this._practiceModule && this._practiceModule.isHide == false) 
            {
                this._practiceModule.updatePetStatus(loc1);
            }
            return;
        }

        private /* var */_practiceModule: IPetPracticeModule;

        private /* var */_petArray: Array<any>;
    }
